package com.ruoyi.web.controller.danger;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.SysHiddenCheck;
import com.ruoyi.system.service.SysHiddenCheckService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.List;

/**
 * 安全隐患三录入(SysHiddenCheck)表控制层
 *
 * @author makejava
 * @since 2022-11-15 15:48:29
 */
@RestController
@RequestMapping("sysHiddenCheck")
public class SysHiddenCheckController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SysHiddenCheckService sysHiddenCheckService;

    /**
     * 分页查询
     *
     * @param sysHiddenCheck 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(SysHiddenCheck sysHiddenCheck) {
        startPage();
        List<SysHiddenCheck> sysHiddenChecks = sysHiddenCheckService.queryByPage(sysHiddenCheck);
        return getDataTable(sysHiddenChecks);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id) {
        return AjaxResult.success(this.sysHiddenCheckService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysHiddenCheck 实体
     * @return 新增结果
     */
    @PostMapping("/create")
    public AjaxResult add(@RequestBody SysHiddenCheck sysHiddenCheck) {
        /*SysHiddenCheck sysHiddenCheck1 = queryYearAndMonth(sysHiddenCheck);
        sysHiddenCheck.setYearD(sysHiddenCheck1.getYearD());
        sysHiddenCheck.setFineGauge(sysHiddenCheck1.getFineGauge());*/

        return AjaxResult.success(this.sysHiddenCheckService.insert(sysHiddenCheck));
    }

    /**
     * 编辑数据
     *
     * @param sysHiddenCheck 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SysHiddenCheck sysHiddenCheck) {
        return AjaxResult.success(this.sysHiddenCheckService.update(sysHiddenCheck));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public AjaxResult deleteById(Integer id) {
        return AjaxResult.success(this.sysHiddenCheckService.deleteById(id));
    }


    private SysHiddenCheck queryYearAndMonth(SysHiddenCheck sysHiddenCheck) {
        Calendar calendar = Calendar.getInstance();
        // 获取当前年
        int year = calendar.get(Calendar.YEAR);
        // 获取当前月
        int month = calendar.get(Calendar.MONTH) + 1;
        if (month >= 6){
            sysHiddenCheck.setYearD(String.valueOf(year));
            sysHiddenCheck.setFineGauge("油气储存企业安全员评估细规（" + year +"年第二次）");
            System.out.println("油气储存企业安全员评估细规（" + year +"年第二次）");
        }else {
            sysHiddenCheck.setYearD(String.valueOf(year));
            sysHiddenCheck.setFineGauge("油气储存企业安全员评估细规（" + year +"年第一次）");
            System.out.println("油气储存企业安全员评估细规（" + year +"年第一次）");
        }
        return sysHiddenCheck;
    }


}

